<template>
	<view class="page">
		<!-- 优惠券tab -->
		<view class="coupon-tab">
			<view class="tab" :class="{'action':TabShow===0}" @click="onCouponTab(0)">
				<text>未使用</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':TabShow===1}" @click="onCouponTab(1)">
				<text>已使用</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':TabShow===-1}" @click="onCouponTab(-1)">
				<text>已过期</text>
				<text class="line"></text>
			</view>
		</view>
		<!-- 优惠券列表 -->
		<view class="coupon-list">
			<view class="list" v-for="(item,index) in couponList" :key="index">
				<view class="list-data" :class="{'coupon-lose':TabShow!=0}">
					<view class="coupon-price">
						<view class="discounts">
							<text class="min">￥</text>
							<text class="max">{{item.coupon.coupon_price}}</text>
						</view>
						<view class="full-reduction"><text>{{item.coupon.title}}</text></view>
						<view class="jag"></view>
					</view>
					<view class="coupon-info">
						<view class="info-title">
							<view class="tag"><text>限品类券</text></view>
							<view class="title"><text>{{item.coupon.discount_method}}</text></view>
						</view>
						<view class="date-get">
							<view class="date"><text>{{item.coupon.end_time}}</text></view>
							<view class="get" @click="onCouponUse" v-if="TabShow===0">
								<text>立即使用</text>
							</view>
						</view>
						<view class="describe-title" @click="isDes=!isDes">
							<text>详细信息</text>
							<text class="iconfont icon-more more" :style="isDes?'transform: rotate(-90deg);':'transform: rotate(90deg);'"></text>
						</view>
					</view>
				</view>
				<view class="use-status" v-if="TabShow != 0">
					<text v-if="TabShow === 1">已使用</text>
					<text v-else-if="TabShow === 2">已过期</text>
				</view>
				<view class="describe" v-show="isDes">
					<text>限品类：尽可购买酒水部分商品</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			TabShow: 0,
			isDes: false,
			couponList:[]
		};
	},
	methods:{
		/**
		 * 优惠券tab点击
		 * @param {Number} type
		 */
		onCouponTab(type){
			this.TabShow = type;
			uni.showLoading({title: '加载中',mask:true});
			this.$http.get('person/mycoupon', {
				status:type
			},{}).then(res => {
				if(res.data.data.length >0){
					this.couponList = res.data.data
					setTimeout(function () {uni.hideLoading();}, 100);
				}else{
					this.couponList = []
					setTimeout(function () {uni.hideLoading();}, 100);
					uni.showToast({
					    title: "没有您要找的数据",
					    duration: 2000,
						icon:"none"
					});
				}
			})
		},
		/**
		 * 去使用点击
		 */
		onCouponUse(){
			uni.navigateTo({
				url: '/pages/SearchGoodsList/SearchGoodsList'
			})
		}
	},
	onLoad() {
		uni.showLoading({title: '加载中',mask:true});
		this.$http.get('person/mycoupon', {
			status:this.TabShow
		},{}).then(res => {
			if(res.data.data.length >0){
				this.couponList = res.data.data
				setTimeout(function () {uni.hideLoading();}, 100);
			}else{
				this.couponList = []
				setTimeout(function () {uni.hideLoading();}, 100);
				uni.showToast({
				    title: "没有您要找的数据",
				    duration: 2000,
					icon:"none"
				});
			}
			
		})
	}
};
</script>

<style scoped lang="scss">
@import 'MyCoupon.scss';
</style>
